<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-flash.min.css">
  <script src="/lib/pace/pace.min.js"></script>


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://kechenhh.gitee.io').hostname,
    root: '/',
    scheme: 'Gemini',
    version: '7.7.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="HTML基础让radio单选框只能选一个——-name相同时，只能选一个 123456&lt;label for&#x3D;&quot;male&quot;&gt;	&lt;input type&#x3D;&quot;radio&quot; id&#x3D;&quot;male&quot; value&#x3D;&quot;男&quot; name&#x3D;&quot;sex&quot;&gt;男&lt;&#x2F;label&gt;&lt;label for&#x3D;&quot;female&quot;&gt;	&lt;input type&#x3D;&quot;radio&quot; id&#x3D;&quot;female">
<meta property="og:type" content="article">
<meta property="og:title" content="HTML5">
<meta property="og:url" content="https://kechenhh.gitee.io/HTML5.html">
<meta property="og:site_name" content="我的博客">
<meta property="og:description" content="HTML基础让radio单选框只能选一个——-name相同时，只能选一个 123456&lt;label for&#x3D;&quot;male&quot;&gt;	&lt;input type&#x3D;&quot;radio&quot; id&#x3D;&quot;male&quot; value&#x3D;&quot;男&quot; name&#x3D;&quot;sex&quot;&gt;男&lt;&#x2F;label&gt;&lt;label for&#x3D;&quot;female&quot;&gt;	&lt;input type&#x3D;&quot;radio&quot; id&#x3D;&quot;female">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-01-14T08:30:15.000Z">
<meta property="article:modified_time" content="2020-12-14T09:47:00.260Z">
<meta property="article:author" content="kechenhh">
<meta property="article:tag" content="HTML5">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://kechenhh.gitee.io/HTML5.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>HTML5 | 我的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle"> my blog</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://kechenhh.gitee.io/HTML5.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="kechenhh">
      <meta itemprop="description" content="学习笔记">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          HTML5
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-01-14 16:30:15" itemprop="dateCreated datePublished" datetime="2020-01-14T16:30:15+08:00">2020-01-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-12-14 17:47:00" itemprop="dateModified" datetime="2020-12-14T17:47:00+08:00">2020-12-14</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/HTML5/" itemprop="url" rel="index">
                    <span itemprop="name">HTML5</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="HTML基础"><a href="#HTML基础" class="headerlink" title="HTML基础"></a>HTML基础</h2><p>让<strong>radio</strong>单选框只能选一个——-name相同时，只能选一个</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">label</span> <span class="attr">for</span>=<span class="string">"male"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"radio"</span> <span class="attr">id</span>=<span class="string">"male"</span> <span class="attr">value</span>=<span class="string">"男"</span> <span class="attr">name</span>=<span class="string">"sex"</span>&gt;</span>男</span><br><span class="line"><span class="tag">&lt;/<span class="name">label</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">label</span> <span class="attr">for</span>=<span class="string">"female"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"radio"</span> <span class="attr">id</span>=<span class="string">"female"</span> <span class="attr">value</span>=<span class="string">"女"</span> <span class="attr">name</span>=<span class="string">"sex"</span>&gt;</span>女</span><br><span class="line"><span class="tag">&lt;/<span class="name">label</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>label</strong>中 for和input中的name相同，可以点击文字选中</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">label</span> <span class="attr">for</span>=<span class="string">"agree"</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"checkbox"</span> <span class="attr">name</span>=<span class="string">""</span> <span class="attr">id</span>=<span class="string">"agree"</span> <span class="attr">value</span>=<span class="string">""</span> /&gt;</span>同意协议</span><br><span class="line"><span class="tag">&lt;/<span class="name">label</span>&gt;</span></span><br></pre></td></tr></table></figure>

<a id="more"></a>


<p><a href="https://www.bilibili.com/video/av51518146" target="_blank" rel="noopener">https://www.bilibili.com/video/av51518146</a></p>
<h2 id="视口viewport"><a href="#视口viewport" class="headerlink" title="视口viewport"></a>视口viewport</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">"viewport"</span> <span class="attr">content</span>=<span class="string">"width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"</span>&gt;</span></span><br></pre></td></tr></table></figure>



<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">

<h2 id="新建html5"><a href="#新建html5" class="headerlink" title="新建html5"></a>新建html5</h2><p>快捷键    html:5  + tab键  或者  ！+ tab键 </p>
<h2 id="语义标签"><a href="#语义标签" class="headerlink" title="语义标签"></a>语义标签</h2><p>nav        导航</p>
<p>header      页眉</p>
<p>footer       页脚</p>
<p>main    文档主要内容</p>
<p>acticle    文章</p>
<p>aside    主题内容之外</p>
<h2 id="兼容问题"><a href="#兼容问题" class="headerlink" title="兼容问题"></a>兼容问题</h2><p>引入 html5shiv 可以解决h5在IE中的兼容性问题</p>
<h2 id="表单"><a href="#表单" class="headerlink" title="表单"></a>表单</h2><h3 id="input-中-type类型"><a href="#input-中-type类型" class="headerlink" title="input 中 type类型"></a>input 中 type类型</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">""</span>&gt;</span></span><br><span class="line">	用户名: <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"username"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	密码：  <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"password"</span> <span class="attr">name</span>=<span class="string">"userPwd"</span>&gt;</span> <span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	</span><br><span class="line">	<span class="comment">&lt;!-- 验证,只能输入邮箱--&gt;</span></span><br><span class="line">	邮箱：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"email"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 移动端弹窗电话拨号 --&gt;</span></span><br><span class="line">	电话：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"tel"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 验证,只能输入网址 --&gt;</span></span><br><span class="line">	网址：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"url"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 增加上下箭头,只能输入数字--&gt;</span></span><br><span class="line">	数量：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"number"</span> <span class="attr">value</span>=<span class="string">"60"</span> <span class="attr">max</span>=<span class="string">"100"</span> <span class="attr">min</span>=<span class="string">"0"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- search：输入框增加删除文字的叉号 --&gt;</span></span><br><span class="line">	请输入商品名称：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"search"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- range范围,拉选条 --&gt;</span></span><br><span class="line">	范围：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"range"</span> <span class="attr">max</span>=<span class="string">"100"</span> <span class="attr">min</span>=<span class="string">"0"</span> <span class="attr">value</span>=<span class="string">"60"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 调用拾色器 --&gt;</span></span><br><span class="line">	颜色：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"color"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 时间和日期 --&gt;</span></span><br><span class="line">	时间：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"time"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	日期：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"date"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- datatime:大多数浏览器不支持，只有苹果的Safari支持 --&gt;</span></span><br><span class="line">	日期时间：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"datetime"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	日期时间：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"datetime-local"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	月份：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"month"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span> </span><br><span class="line">	星期：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"week"</span>&gt;</span></span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> <span class="attr">value</span>=<span class="string">"提交"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="表单新增属性"><a href="#表单新增属性" class="headerlink" title="表单新增属性"></a>表单新增属性</h3><ul>
<li>placeholder：提示文本</li>
<li>autofocus：自动获取焦点</li>
<li>autocomplete：自动完成</li>
<li>required:必须输入</li>
<li>pattern:正则表达式验证</li>
<li>multiple：可选择多个文件</li>
<li>form：指定表单id,当前不在form标签中的表单数据也会提交</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">""</span> <span class="attr">id</span>=<span class="string">"myForm"</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- placeholder：提示文本 --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- autofocus：自动获取焦点 --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- autocomplete：自动完成，on:打开 off:关闭 --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--autocomplete执行需要同时满足两个前提：</span></span><br><span class="line"><span class="comment">	1.必须成功提交过</span></span><br><span class="line"><span class="comment">	2.当前添加autocomplete的元素必须有name属性 --&gt;</span></span><br><span class="line">	用户名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"username"</span> <span class="attr">placeholder</span>=<span class="string">"请输入用户名"</span> <span class="attr">autofocus</span> <span class="attr">autocomplete</span>=<span class="string">"on"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	</span><br><span class="line">	<span class="comment">&lt;!-- required:必须输入 --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- pattern:正则表达式验证 --&gt;</span></span><br><span class="line">	手机号：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"tel"</span> <span class="attr">name</span>=<span class="string">"userphone"</span> <span class="attr">required</span> <span class="attr">pattern</span>=<span class="string">"^1(3|4|5|6|7|8|9)\d&#123;9&#125;$"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	</span><br><span class="line">	<span class="comment">&lt;!-- multiple：可选择多个文件 --&gt;</span></span><br><span class="line">	文件：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"file"</span> <span class="attr">name</span>=<span class="string">"photo"</span> <span class="attr">multiple</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 在email中multiple允许输入多个邮箱，用逗号分隔 --&gt;</span></span><br><span class="line">	邮箱：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"email"</span> <span class="attr">name</span>=<span class="string">"email"</span> <span class="attr">multiple</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 提交: --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span>&gt;</span><span class="tag">&lt;/<span class="name">input</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- form：指定表单id,当前不在form标签中的表单数据也会提交 --&gt;</span></span><br><span class="line">地址：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"address"</span> <span class="attr">form</span>=<span class="string">"myForm"</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="HTML5-表单元素"><a href="#HTML5-表单元素" class="headerlink" title="HTML5 表单元素"></a>HTML5 表单元素</h3><ul>
<li>datalist</li>
<li>keygen（浏览器基本不支持）</li>
<li>output</li>
</ul>
<h3 id="表单新增事件"><a href="#表单新增事件" class="headerlink" title="表单新增事件"></a>表单新增事件</h3><ul>
<li>oninput:监听当前指定元素内容的改变</li>
<li>onkeyup:键盘弹起的时候触发：每一个键的弹起都会触发一次</li>
<li>oninvalid:当验证不通过的时候触发</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">""</span> <span class="attr">method</span>=<span class="string">"post"</span>&gt;</span></span><br><span class="line">	用户名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span>  <span class="attr">name</span>=<span class="string">"userName"</span> <span class="attr">id</span>=<span class="string">"userName"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	电话：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"tel"</span> <span class="attr">name</span>=<span class="string">"userPhone"</span> <span class="attr">id</span>=<span class="string">"userPhone"</span> <span class="attr">pattern</span>=<span class="string">"^1\d&#123;10&#125;$"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- 提交 --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> <span class="attr">value</span>=<span class="string">"提交"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="javascript">	ouserName = <span class="built_in">document</span>.getElementById(<span class="string">"userName"</span>)</span></span><br><span class="line"><span class="javascript">	ouserPhone = <span class="built_in">document</span>.getElementById(<span class="string">"userPhone"</span>)</span></span><br><span class="line"><span class="actionscript">	<span class="comment">// oninput:监听当前指定元素内容的改变</span></span></span><br><span class="line"><span class="actionscript">	ouserName.oninput=<span class="function"><span class="keyword">function</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="javascript">		<span class="built_in">console</span>.log(<span class="string">'oninput:'</span>+<span class="keyword">this</span>.value);</span></span><br><span class="line">	&#125;</span><br><span class="line"><span class="actionscript">	<span class="comment">//onkeyup:键盘弹起的时候触发：每一个键的弹起都会触发一次</span></span></span><br><span class="line"><span class="actionscript">	ouserName.onkeyup=<span class="function"><span class="keyword">function</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="javascript">		<span class="built_in">console</span>.log(<span class="string">'onkeyup:'</span>+<span class="keyword">this</span>.value);</span></span><br><span class="line">	&#125;</span><br><span class="line"><span class="actionscript">	<span class="comment">//oninvalid:当验证不通过的时候触发</span></span></span><br><span class="line"><span class="actionscript">	ouserPhone.oninvalid=<span class="function"><span class="keyword">function</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="actionscript">		<span class="comment">//设置默认的提示信息</span></span></span><br><span class="line"><span class="actionscript">		<span class="keyword">this</span>.setCustomValidity(<span class="string">"请输入合法的11位手机号"</span>)</span></span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="进度条-progress-和度量器（meter）"><a href="#进度条-progress-和度量器（meter）" class="headerlink" title="进度条(progress)和度量器（meter）"></a>进度条(progress)和度量器（meter）</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- progress:进度条 --&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- max:最大值,value:当前进度值 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">progress</span> <span class="attr">max</span>=<span class="string">"100"</span> <span class="attr">value</span>=<span class="string">"50"</span>&gt;</span><span class="tag">&lt;/<span class="name">progress</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!--meter:度量器</span></span><br><span class="line"><span class="comment">high:规定的较高的值，low:规定的较高的值</span></span><br><span class="line"><span class="comment">max:最大值，min:最小值，value:当前值 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meter</span> <span class="attr">max</span>=<span class="string">"100"</span> <span class="attr">min</span>=<span class="string">"0"</span> <span class="attr">high</span>=<span class="string">"80"</span> <span class="attr">low</span>=<span class="string">"40"</span> <span class="attr">value</span>=<span class="string">"30"</span>&gt;</span><span class="tag">&lt;/<span class="name">meter</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meter</span> <span class="attr">max</span>=<span class="string">"100"</span> <span class="attr">min</span>=<span class="string">"0"</span> <span class="attr">high</span>=<span class="string">"80"</span> <span class="attr">low</span>=<span class="string">"40"</span> <span class="attr">value</span>=<span class="string">"50"</span>&gt;</span><span class="tag">&lt;/<span class="name">meter</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">meter</span> <span class="attr">max</span>=<span class="string">"100"</span> <span class="attr">min</span>=<span class="string">"0"</span> <span class="attr">high</span>=<span class="string">"80"</span> <span class="attr">low</span>=<span class="string">"40"</span> <span class="attr">value</span>=<span class="string">"90"</span>&gt;</span><span class="tag">&lt;/<span class="name">meter</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h2 id="多媒体标签-autio和video"><a href="#多媒体标签-autio和video" class="headerlink" title="多媒体标签(autio和video)"></a>多媒体标签(autio和video)</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 	autio:音频</span></span><br><span class="line"><span class="comment">		src:音频文件所在的路径</span></span><br><span class="line"><span class="comment">		controls:音频播放器的控制面板</span></span><br><span class="line"><span class="comment">		autoplay:自动播放</span></span><br><span class="line"><span class="comment">		loop:循环 --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">audio</span> <span class="attr">src</span>=<span class="string">"晚安.mp3"</span> <span class="attr">controls</span> <span class="attr">loop</span>&gt;</span><span class="tag">&lt;/<span class="name">audio</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 	video:视频</span></span><br><span class="line"><span class="comment">		src:视频文件所在的路径</span></span><br><span class="line"><span class="comment">		controls:视频播放器的控制面板</span></span><br><span class="line"><span class="comment">		autoplay:自动播放</span></span><br><span class="line"><span class="comment">		loop:循环</span></span><br><span class="line"><span class="comment">		width:宽度</span></span><br><span class="line"><span class="comment">		height:高度</span></span><br><span class="line"><span class="comment">		poster:封面--&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- 注意：只设置宽度或者高度，可以等比例 --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">video</span> <span class="attr">src</span>=<span class="string">"./视频.mp4"</span> <span class="attr">controls</span> <span class="attr">poster</span>=<span class="string">"./1.jpg"</span> <span class="attr">width</span>=<span class="string">"500px"</span> &gt;</span><span class="tag">&lt;/<span class="name">video</span>&gt;</span></span><br><span class="line">		</span><br><span class="line">		<span class="comment">&lt;!-- source:因为不同浏览器支持的视频格式不同，可以准备不同格式的视频文件 --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">video</span> <span class="attr">controls</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">source</span> <span class="attr">src</span>=<span class="string">"./视频.mp4"</span> <span class="attr">type</span>=<span class="string">"video/mp4"</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">source</span> <span class="attr">src</span>=<span class="string">"./视频.flv"</span> <span class="attr">type</span>=<span class="string">"video/flv"</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">video</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="Dom操作"><a href="#Dom操作" class="headerlink" title="Dom操作"></a>Dom操作</h2><ul>
<li>querySelector(传入选择器的名称)</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">"red"</span>&gt;</span>前端<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">"green"</span>&gt;</span>java<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">li</span> <span class="attr">class</span>=<span class="string">"blue"</span>&gt;</span>javascript<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">li</span>&gt;</span>c++<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="javascript">	<span class="built_in">window</span>.onload=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span></span><br><span class="line">		</span><br><span class="line"><span class="actionscript">		<span class="comment">// query:查询			Selector:选择器		</span></span></span><br><span class="line"><span class="actionscript">		<span class="comment">//querySelector(传入选择器的名称):选择单个，多个时返回满足条件的第一个</span></span></span><br><span class="line"><span class="javascript">		<span class="keyword">var</span> javaLi=<span class="built_in">document</span>.querySelector(<span class="string">".green"</span>);</span></span><br><span class="line"><span class="javascript">		<span class="built_in">console</span>.log(javaLi);</span></span><br><span class="line"><span class="actionscript">		<span class="comment">//querySelectorAll():返回满足条件的所有，数组</span></span></span><br><span class="line"><span class="javascript">		<span class="keyword">var</span> allLi=<span class="built_in">document</span>.querySelectorAll(<span class="string">'li'</span>);</span></span><br><span class="line"><span class="javascript">		<span class="built_in">console</span>.log(allLi)</span></span><br><span class="line">	&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="自定义属性"><a href="#自定义属性" class="headerlink" title="自定义属性"></a>自定义属性</h2><p>规范：<br>1.以data-开头</p>
<p>2.data-后必须至少有一个字符，多个单词使用-连接</p>
<p>建议：<br>1.名称应该都使用小写-不要包含任何的大写字符</p>
<p>2.名称中不要有任何的特殊符号</p>
<p>3.名称不要副作用纯数</p>
<p>取值方法：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">data-school-name</span> = <span class="string">"itcast"</span>&gt;</span>学校名<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="javascript">	<span class="built_in">window</span>.onload=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span></span><br><span class="line"><span class="javascript">		<span class="keyword">var</span> p = <span class="built_in">document</span>.querySelector(<span class="string">'p'</span>)</span></span><br><span class="line"><span class="actionscript">		<span class="comment">//获取自定义属性值</span></span></span><br><span class="line"><span class="actionscript">		<span class="comment">// 将data-后面的单词使用camel命名法（驼峰命名）连接</span></span></span><br><span class="line"><span class="actionscript">		<span class="keyword">var</span> value = p.dataset[<span class="string">"schoolName"</span>];</span></span><br><span class="line"><span class="javascript">		<span class="built_in">console</span>.log(value);</span></span><br><span class="line">	&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="接口"><a href="#接口" class="headerlink" title="接口"></a>接口</h2><h3 id="网络接口"><a href="#网络接口" class="headerlink" title="网络接口"></a>网络接口</h3><ul>
<li>ononline:网络连通的时候触发这个事件</li>
<li>onoffline:网络断开时触发</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// ononline:网络连通的时候触发这个事件</span></span><br><span class="line"><span class="comment">// addEventListener添加事件（为了兼容移动端）--事件不加on</span></span><br><span class="line"><span class="built_in">window</span>.addEventListener(<span class="string">"online"</span>,<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	alert(<span class="string">'网络连通了'</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//onoffline:网络断开时触发</span></span><br><span class="line"><span class="built_in">window</span>.addEventListener(<span class="string">"offline"</span>,<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	alert(<span class="string">'网络断开了'</span>);</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="全屏接口"><a href="#全屏接口" class="headerlink" title="全屏接口"></a>全屏接口</h3><p>全屏操作的主要方法和属性</p>
<p>1.requestFullScreen():开启全屏<br><strong>不同浏览器需要添加不同的前缀</strong><br>chrome:webkit        firefox:moz        ie:ms        opera:o<br>2.CancelFullScreen():退出全屏,操作的是document<br>3.fullScreenElement:判断是否是全屏状态,判断的是document</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">window</span>.onload=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">var</span> div = <span class="built_in">document</span>.querySelector(<span class="string">"div"</span>);</span><br><span class="line">	<span class="comment">// 添加三个按钮的点击事件</span></span><br><span class="line">	<span class="comment">// 全屏操作</span></span><br><span class="line">	<span class="built_in">document</span>.querySelector(<span class="string">"#full"</span>).onclick=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="comment">// div.webkitRequestFullScreen()</span></span><br><span class="line">		<span class="comment">// 使用能力测试添加不同浏览器下的前缀</span></span><br><span class="line">	<span class="keyword">if</span>(div.RequestFullScreen)&#123;</span><br><span class="line">			div.RequestFullScreen();</span><br><span class="line">		&#125;<span class="keyword">else</span> <span class="keyword">if</span>(div.webkitRequestFullScreen)&#123;</span><br><span class="line">			div.webkitRequestFullScreen();</span><br><span class="line">		&#125;<span class="keyword">else</span> <span class="keyword">if</span>(div.mozRequestFullScreen)&#123;</span><br><span class="line">			div.mozRequestFullScreen();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">             <span class="comment">//退出全屏</span></span><br><span class="line">	<span class="built_in">document</span>.querySelector(<span class="string">"#cancelFull"</span>).onclick=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">if</span>(<span class="built_in">document</span>.CancelFullScreen)&#123;</span><br><span class="line">			<span class="built_in">document</span>.CancelFullScreen();</span><br><span class="line">		&#125;<span class="keyword">else</span> <span class="keyword">if</span>(<span class="built_in">document</span>.webkitCancelFullScreen)&#123;</span><br><span class="line">			<span class="built_in">document</span>.webkitCancelFullScreen();</span><br><span class="line">		&#125;<span class="keyword">else</span> <span class="keyword">if</span>(<span class="built_in">document</span>.mozCancelFullScreen())&#123;</span><br><span class="line">			<span class="built_in">document</span>.mozCancelFullScreen();</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="FileReader-p19"><a href="#FileReader-p19" class="headerlink" title="FileReader    p19"></a>FileReader    p19</h3><ul>
<li><p>readAsText():读取文本文件</p>
</li>
<li><p>readAsBinaryString():读取任意类型的文件，返回二进制字符串</p>
</li>
<li><p>readAsDataURL():读取文件获取一段以data开头的字符串</p>
</li>
<li><p>abort():中断读取</p>
</li>
</ul>
<p>需求–即时预览</p>
<h3 id="拖拽接口"><a href="#拖拽接口" class="headerlink" title="拖拽接口"></a>拖拽接口</h3><h3 id="地理定位接口"><a href="#地理定位接口" class="headerlink" title="地理定位接口"></a>地理定位接口</h3><h2 id="Web存储"><a href="#Web存储" class="headerlink" title="Web存储"></a>Web存储</h2><h3 id="sessionStorage"><a href="#sessionStorage" class="headerlink" title="sessionStorage"></a>sessionStorage</h3><p>存储数据到本地，容量5mb左右</p>
<p>1.存储在当前页面中</p>
<p>2.它的的生命周期为关闭当前页面，关闭页面，数据自动清除</p>
<ul>
<li>setItem(key,value):以键值对的方式存储数据，存储在当前页面中</li>
<li>getItem(“key”):读取数据</li>
<li>removeItem(“key”):删除指定键的数据</li>
<li>clear():删除所有数据</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> oSetData = <span class="built_in">document</span>.querySelector(<span class="string">"#setData"</span>);</span><br><span class="line">	<span class="keyword">var</span> oGetData = <span class="built_in">document</span>.querySelector(<span class="string">"#getData"</span>);</span><br><span class="line">	<span class="keyword">var</span> oRemoveData = <span class="built_in">document</span>.querySelector(<span class="string">"#removeData"</span>);</span><br><span class="line"></span><br><span class="line">	<span class="comment">//存储数据setItem()</span></span><br><span class="line">	oSetData.onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="comment">// 获取用户名</span></span><br><span class="line">		<span class="keyword">var</span> name = <span class="built_in">document</span>.querySelector(<span class="string">"#userName"</span>).value;</span><br><span class="line">		<span class="comment">//存储数据</span></span><br><span class="line">		<span class="built_in">window</span>.sessionStorage.setItem(<span class="string">"userName"</span>,name);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//读取数据:getItem()</span></span><br><span class="line">	oGetData.onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="keyword">var</span> name = <span class="built_in">window</span>.sessionStorage.getItem(<span class="string">"userName"</span>);</span><br><span class="line">		alert(name);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//删除数据</span></span><br><span class="line">	oRemoveData.onclick=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="built_in">window</span>.sessionStorage.removeItem(<span class="string">"userName"</span>)</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<h3 id="localStorage"><a href="#localStorage" class="headerlink" title="localStorage"></a>localStorage</h3><p>方法同sessionStorage</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/HTML5/" rel="tag"># HTML5</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/%E7%88%B6%E5%AD%90%E7%BB%84%E4%BB%B6.html" rel="prev" title="父子组件">
      <i class="fa fa-chevron-left"></i> 父子组件
    </a></div>
      <div class="post-nav-item">
    <a href="/%E5%8A%A0%E5%AF%86%E6%96%87%E7%AB%A0.html" rel="next" title="加密文章">
      加密文章 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#HTML基础"><span class="nav-number">1.</span> <span class="nav-text">HTML基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#视口viewport"><span class="nav-number">2.</span> <span class="nav-text">视口viewport</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#新建html5"><span class="nav-number">3.</span> <span class="nav-text">新建html5</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#语义标签"><span class="nav-number">4.</span> <span class="nav-text">语义标签</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#兼容问题"><span class="nav-number">5.</span> <span class="nav-text">兼容问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#表单"><span class="nav-number">6.</span> <span class="nav-text">表单</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#input-中-type类型"><span class="nav-number">6.1.</span> <span class="nav-text">input 中 type类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#表单新增属性"><span class="nav-number">6.2.</span> <span class="nav-text">表单新增属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HTML5-表单元素"><span class="nav-number">6.3.</span> <span class="nav-text">HTML5 表单元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#表单新增事件"><span class="nav-number">6.4.</span> <span class="nav-text">表单新增事件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#进度条-progress-和度量器（meter）"><span class="nav-number">7.</span> <span class="nav-text">进度条(progress)和度量器（meter）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多媒体标签-autio和video"><span class="nav-number">8.</span> <span class="nav-text">多媒体标签(autio和video)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Dom操作"><span class="nav-number">9.</span> <span class="nav-text">Dom操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自定义属性"><span class="nav-number">10.</span> <span class="nav-text">自定义属性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#接口"><span class="nav-number">11.</span> <span class="nav-text">接口</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#网络接口"><span class="nav-number">11.1.</span> <span class="nav-text">网络接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全屏接口"><span class="nav-number">11.2.</span> <span class="nav-text">全屏接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#FileReader-p19"><span class="nav-number">11.3.</span> <span class="nav-text">FileReader    p19</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#拖拽接口"><span class="nav-number">11.4.</span> <span class="nav-text">拖拽接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#地理定位接口"><span class="nav-number">11.5.</span> <span class="nav-text">地理定位接口</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Web存储"><span class="nav-number">12.</span> <span class="nav-text">Web存储</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#sessionStorage"><span class="nav-number">12.1.</span> <span class="nav-text">sessionStorage</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#localStorage"><span class="nav-number">12.2.</span> <span class="nav-text">localStorage</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="kechenhh"
      src="/images/avatar.gif">
  <p class="site-author-name" itemprop="name">kechenhh</p>
  <div class="site-description" itemprop="description">学习笔记</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">19</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/kechenhh" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;kechenhh" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">kechenhh</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.0
  </div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
